package com.hqyj.javaSpringBoot.modules.account.dao;

import com.hqyj.javaSpringBoot.modules.account.entity.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserRoleDao {

    /**
     * 在 account_user_role 表中添加用户和角色的 id
     * @param userRole
     */
    @Insert("insert into account_user_role (user_id, role_id) " +
            "values(#{userId}, #{roleId})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insertUserRole(UserRole userRole);

    /**
     * 通过 userId 删除记录
     * @param userId
     */
    @Delete("delete from account_user_role where user_id = #{userId}")
    void deleteUserRoleByUserId(Integer userId);

    /**
     * 通过 roleId 删除记录
     * @param roleId
     */
    @Delete("delete from account_user_role where role_id = #{roleId}")
    void deleteUserRoleByRoleId(int roleId);
}
